package cn.shadow.result;


/**
 * 通用返回类型
 * @author 冯啸迪
 */
public class ResultData<T> {

    static enum Enums{
        /**
         * 0失败
         * 1成功
         */
        SUCCESS((byte) 1,"成功"),
        FAIL((byte)0, "失败");

        private final Byte status;
        private final String name;

        Enums(Byte status, String name) {
            this.status = status;
            this.name = name;
        }

        public Byte getStatus() {
            return status;
        }

        public String getName() {
            return name;
        }
    }

    private Byte status;

    private String message;

    private T data;

    public ResultData() {
    }

    public ResultData(Byte status, String message, T data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    public static ResultData success(){
        return new ResultData(Enums.SUCCESS.getStatus(), "SUCCESS", null);
    }

    public static ResultData success(Object data){
        return new ResultData(Enums.SUCCESS.getStatus(), "SUCCESS", data);

    }

    public static ResultData fail(){
        return new ResultData(Enums.FAIL.getStatus(), "FAIL", null);
    }

    public static ResultData fail(String message){
        return new ResultData(Enums.FAIL.getStatus(), message, null);
    }

    public Byte getStatus() {
        return status;
    }

    public void setStatus(Byte status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
